<template>
	<view class="page">
		<view class="news">
			<news-content :list="list" @del="del"></news-content>
		</view>
	</view>
</template>

<script>
	import {
		getAllMyMessage,
		deleteMyMessage
	} from '@/api/message/message.js';
	export default {
		onShow() {
			getAllMyMessage().then((Response) => {
				console.log(Response.rows)
				this.list = Response.rows;
				for (let i = 0; i < this.list.length; i++) {
					if (this.list[i].mgsStatus == 0) {
						this.list[i].mgsStatus = "这是一条系统消息"
					} else if (this.list[i].mgsStatus == 1) {
						this.list[i].mgsStatus = "这是一条活动消息"
					} else if (this.list[i].mgsStatus == 2) {
						this.list[i].mgsStatus = "这是一条谏言消息"
					}
				}
			})
		},
		onHide() {
			getAllMyMessage().then((Response) => {
				this.list = Response.rows;
				for (let i = 0; i < this.list.length; i++) {
					if (this.list[i].mgsStatus == 0) {
						this.list[i].mgsStatus = "这是一条系统消息"
					} else if (this.list[i].mgsStatus == 1) {
						this.list[i].mgsStatus = "这是一条活动消息"
					} else if (this.list[i].mgsStatus == 2) {
						this.list[i].mgsStatus = "这是一条谏言消息"
					}
				}
			})
		},
		data() {
			return {
				list: []
			}
		},
		//监听下拉刷新
		onPullDownRefresh() {
			this.refresh()
		},
		methods: {
			del(id) {
				deleteMyMessage(id)
				setTimeout(() => {
					getAllMyMessage().then((Response) => {
						this.list = Response.rows;
						for (let i = 0; i < this.list.length; i++) {
							if (this.list[i].mgsStatus == 0) {
								this.list[i].mgsStatus = "这是一条系统消息"
							} else {
								this.list[i].mgsStatus = "这是一条活动消息"
							}
						}
					})
				}, 100)
			},
			//下拉刷新
			refresh() {

				setTimeout(() => {
					// 此处可写下拉更新消息逻辑
					getAllMyMessage().then((Response) => {
						this.list = Response.rows;
						for (let i = 0; i < this.list.length; i++) {
							if (this.list[i].mgsStatus == 0) {
								this.list[i].mgsStatus = "这是一条系统消息"
							} else {
								this.list[i].mgsStatus = "这是一条活动消息"
							}
						}
					})
					uni.stopPullDownRefresh();
				}, 1000)
				//停止下拉刷新

			}
		},
	}
</script>

<style lang="scss">
	.news {
		width: 100%;
		height: 100%;
		background: #ffffff;
		// margin-top: 10px;
	}
	
	page {
		background-image: url(../../static/images/hd.png);

	}
</style>
